/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.daoimpl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.sesame.dao.ImageDAO;
import com.sesame.domain.Album;
import com.sesame.domain.Image;
import com.sesame.toolkit.Page;

/**
 * @author voidman
 * 
 */
public class ImageDAOImpl extends SqlMapClientDaoSupport implements ImageDAO {

    public void addImage(Image Image) {
        getSqlMapClientTemplate().insert("addImage", Image);
    }

    public void deleteImageById(Integer id) {
        getSqlMapClientTemplate().delete("deleteImageById", id);
    }

    public void deleteImageByAlbumId(Integer albumId) {
        getSqlMapClientTemplate().delete("deleteImageByAlbumId", albumId);
    }

    @SuppressWarnings("unchecked")
    public List<Image> getAllImage() {
        return (List<Image>) getSqlMapClientTemplate().queryForList(
                "getAllImage");
    }

    public List<Image> getTopImageByUserId(Integer userId) {
        return (List<Image>) getSqlMapClientTemplate().queryForList(
                "getTopImageByUserId", userId);
    }

    public List<Image> getImageByAlbumId(Page page) {
        return (List<Image>) getSqlMapClientTemplate().queryForList(
                "getPageImageByAlbumId", page);
    }

    public List<Image> getImageByUserId(Integer userId) {
        return (List<Image>) getSqlMapClientTemplate().queryForList(
                "getImageByUserId", userId);
    }

    public Image getImageById(Integer id) {
        return (Image) getSqlMapClientTemplate().queryForObject("getImageById",
                id);
    }

    public List<Image> getImageByAlbumId(Integer albumId) {
        return (List<Image>) getSqlMapClientTemplate().queryForList(
                "getImageByAlbumId", albumId);
    }

    public void updateImage(Image Image) {
        getSqlMapClientTemplate().update("updateImage", Image);
    }

    public void updateImagePrivacy(Image Image) {
        getSqlMapClientTemplate().update("updateImagePrivacy", Image);
    }

    public List<Image> getTopImage() {
        return (List<Image>) getSqlMapClientTemplate().queryForList(
                "getTopImage");
    }

    public void updateVisitAmount(Integer id) {
        getSqlMapClientTemplate().update("updateImageVisitAmount", id);
    }

    public Integer getImageCount(Integer albumId) {
        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getImageCount", albumId);
    }

    public Integer getUserImageCount(Integer userId) {
        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getUserImageCount", userId);
    }

    public List<Image> getAllImage(Page page) {
        return (List<Image>) getSqlMapClientTemplate().queryForList(
                "getPageImage", page);
    }

    public List<Image> getImageByUserId(Page page) {
        return (List<Image>) getSqlMapClientTemplate().queryForList(
                "getPageImageByUserId", page);
    }

    public Integer getAllImageCount() {
        return (Integer) getSqlMapClientTemplate().queryForObject(
                "getAllImageCount");
    }
}